﻿@using System.Collections.Specialized
@using MvcApplication.Entity
@{
    NameValueCollection param = Request.QueryString;
    string request = string.Empty;

    foreach (var p in param)
    {
        if ((string)p != "pageIndex")
        {
            request = request + p + "=" + Request.QueryString[(string)p] + "&";
        }
    }
}



<div class="pagination">
    <ul>
        @if (Model.PageIndex <= 1)
        {
            <li class="disabled"><a href="#">&laquo;</a></li>
        }
        else
        {
            <li>
                <a href="?@(request)pageIndex=@Html.Raw(Model.PageIndex - 1)">&laquo;</a>
            </li>
        }


        @{
            int pageCount = Model.PageCount - Model.PageIndex > 10 ? Model.PageIndex + 9 : Model.PageCount;
            int pageStart = Model.PageIndex - 5 < 1 ? 1 : Model.PageIndex - 4;

            for (int i = pageStart; i <= pageCount; i++)
            {
                if (Model.PageIndex == i)
                {
            <li class="active"><a href="">@i</a></li>
                }
                else
                {
            <li>
                <a href="?@(request)pageIndex=@i">@i</a>
            </li>
                }

            }

            if (Model.PageIndex >= Model.PageCount)
            {
            <li class="disabled"><a href="#">&raquo;</a></li>
            }
            else
            {
            <li>
                <a href="?@(request)pageIndex=@Html.Raw(Model.PageIndex + 1)">&raquo;</a>
            </li>
            }
        }
        <li class="disabled pagination-info"><a href="#">当前第@(Model.PageIndex)/@(Model.PageCount)页</a></li>
        <li class="disabled pagination-info"><a href="#">共@(Model.PageCount)条记录</a></li>
    </ul>
</div>
